using Gateway.Common.Enums;
using Gateway.Common.Extensions;
using Gateway.Domain.EFCore.Configuration;
using Gateway.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Gateway.Domain.Configuration;

public class RequestLogConfiguration : AggregateRootEntityConfiguration<RequestLog>
{
    public override void Configure(EntityTypeBuilder<RequestLog> builder)
    {
        builder.ToTable(t => t.HasComment("请求日志"));
        base.Configure(builder);
        builder.Property(x => x.LogType).IsRequired().HasMaxLength(50).HasComment("日志类型");
        builder.Property(x => x.LogName).IsRequired().HasMaxLength(1000).HasComment("日志名称");
        builder.Property(x => x.ApiPath).HasMaxLength(500).HasComment("请求路径");
        builder.Property(x => x.HttpMethod).HasMaxLength(50).HasComment("请求方法 http method POST GET PUT DELETE");
        builder.Property(x => x.Ip).HasMaxLength(200).HasComment("客户端ip");
        builder.Property(x => x.Event).HasColumnType("text").HasComment("日志具体的内容");
        builder.HasIndex(p => new { p.LogType });
    }
}